package map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test {
    public static void main(String[] args) {
        /*Map<Character, Integer> map = new HashMap<>();
        String strSource = "Hello world! thinking in java! I love java!";

        int length = strSource.length();
        for (int i = 0; i < length; i++) {
            Set<Character> characters = map.keySet();

            char s = strSource.charAt(i);
            if (!characters.contains(s)) {
                map.put(s, 1);
            } else {
                int num = map.get(s);
                map.put(s, num + 1);
            }
        }
        System.out.println(map);*/

        String str = "Hello everyone! My name is ZhangSan...";
        Map<Character,Integer> map = new HashMap<>();
        int length = str.length();
        for(int i = 0;i < length; i++){
            Set<Character> chars = map.keySet();
            char c = str.charAt(i);
            if(chars.contains(c)){
                int num = map.get(c);
                map.put(c,num+1);
            }else{
                map.put(c,1);
            }
        }
        System.out.println(map);
    }
}
